var preState = 0
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [{
        name: '推荐排序',
        roomState: 0,
        isSelected: false,
        image: '../../images/default_sort.png'
      },
      {
        name: '价格低-高',
        roomState: 1,
        isSelected: false,
        image: '../../images/price_bellow_to_top.png'
      },
      {
        name: '价格高-低',
        roomState: 2,
        isSelected: false,
        image: '../../images/price_top_to_bellow.png'
      },
      {
        name: '评分高-低',
        roomState: 3,
        isSelected: false,
        image: '../../images/most_popular.png'
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getIntentData(options)
  },
  /** 
   * 传递数据
   */
  getIntentData(options) {
    var state = options.sort
    var selected = 'list[' + state + '].isSelected'
    var roomState = 'list[' + state + '].roomState'
    this.setData({
      [selected]: true,
      [roomState]: state
    })
    preState = state
  },
  /**
   * 选择排序方式
   */
  clickRecommendType: function(e) {
    var index = e.currentTarget.dataset.id
    var dd = this.data.list
    var selected = 'list[' + index + '].isSelected'
    var preSelected = 'list[' + preState + '].isSelected'
    var name = dd[index].name
    this.setData({
      [selected]: true,
      [preSelected]: false
    })
    preState = index
    var pages = getCurrentPages()
    var curPage = pages[pages.length - 1]
    var prePage = pages[pages.length - 2]
    prePage.setData({
      bingPage: 1,
      messageCode: "",
      list: null,
      isGetData: false,
      iss: true,
      sort: preState,
      recommendType: name
    })
    prePage.connectNetForData()
    wx.navigateBack({
      delta: 1
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})